package com.xmin.lecture.manus.agent;

import com.xmin.lecture.manus.tool.BrowserUseTool;
import com.xmin.lecture.manus.tool.FileSaverTool;
import com.xmin.lecture.manus.tool.PythonPackageInstaller;
import com.xmin.lecture.manus.tool.PythonTool;
import com.xmin.lecture.manus.tool.SearchTool;
import com.xmin.lecture.manus.tool.TerminateTool;
import com.xmin.lecture.manus.tool.Tool;
import com.xmin.lecture.manus.tool.ToolResult;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import java.util.List;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@Slf4j
public abstract class Agent {

    public abstract ChatLanguageModel getLanguageModel();

    public abstract ChatMemory getMemory();

    public abstract String getPrompt();

    public List<Tool> tools = List.of(
        new FileSaverTool(),
        new SearchTool(),
        new PythonTool(),
        new PythonPackageInstaller(),
        new BrowserUseTool(),
        new TerminateTool());

    private int maxSteps = 10;

    private int currentStep = 1;

    public abstract ToolResult step();

    public void run() {
        AgentState state = AgentState.RUNNING;
        while (currentStep < maxSteps && state != AgentState.FINISHED) {
            log.info("开始执行步骤：{} / {} ", currentStep, maxSteps);
            ToolResult toolResult = step();
            log.info("步骤 {} 执行结果为：{}", currentStep, toolResult.getResult());
            currentStep++;
            state = toolResult.getState();
            if (currentStep >= maxSteps) {
                log.info("Current step exceeded max steps: {} ", currentStep);
            }

        }
    }


}
